package com.yinanxi.lflume;

import org.apache.flume.Context;
import org.apache.flume.Event;
import org.apache.flume.interceptor.Interceptor;

import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * @Created by Orion
 * @Description
 *  为来的数据打上标签
 */
public class MyEventSelector implements Interceptor {
    Random random = null ;
    public void initialize() {
         random = new Random();
    }
    public Event intercept(Event event) {
        Map<String, String> headers = event.getHeaders();
     headers.put("state" , random.nextInt(2)+"") ;
        return event;
    }

    public List<Event> intercept(List<Event> events) {
        for (Event event : events) {
            intercept(event) ;
        }
        return events;
    }

    public void close() {
        random = null  ;
    }
 // 拦截器 构建器
    public  static  class MyEventSelectorBuilder implements Interceptor.Builder{

     public Interceptor build() {
         return new MyEventSelector();
     }

     public void configure(Context context) {

     }
 }


}
